<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>webworker</title>
</head>

<body>


  <button id="btn">大量计算</button>
  <input type="text">
  <script>
    // 创建一个 Web Worker 实例
    var worker = new Worker('worker.js');

    document.getElementById('btn').addEventListener('click', function () {
      // 向 Web Worker 发送消息
      worker.postMessage({ type: '计算', count: 1000000000 });
    })
    // 监听 Web Worker 的消息
    worker.onmessage = function (event) {
      var result = event.data;
      console.log('Result:', result); // 输出文件处理结果
    };

  </script>
</body>

</html>